import axios from "axios";


//一级分类
//http://00000.work:19099/shopping/headline
export function getShoppingHeadline(){
    return axios.get(`/work/shopping/headline`)
}

//二级分类+数据显示
//传递参数
// http://00000.work:19099/shopping/from?commodity=现实商品
export function getShoppingFrom(commodity){
    return axios.get(`/work/shopping/from?commodity=${commodity}`)
}



//根据id查询商品信息
//传递参数
// http://00000.work:19099/shopping/fromid?id=3
export function getShoppingFromid(id){
    return axios.get(`/work/shopping/fromid?id=${id}`)
}


// http://00000.work:19099/login/login?name=zs4&password=123456
// 获取到的Authorization需要保存起来：
//eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLmma7pgJrnlKjmiLciLCJleHAiOjE2OTM3NDU0MTgsImlzcyI6IlNLLTAwMDAwLndvcmsiLCJqd3Rtb2RlbCI6IntcIm5pY2tuYW1lXCI6XCJ6czRcIixcInR5cGVcIjpcImRlZmF1bHRcIixcInVpZFwiOlwiODE4OWQzMzAwNjYxNGUxNWFlOTZcIn0ifQ.OGbpNvSBWHLkqMn7-dRl_buBw_Z4RbiX5TATJkZOKC2S85oO8xP5bRoAMrtUOIdng02ZOxXRr31BJL7YUvAbqg
export function getLoginShopping(username,password){
    // ?name=zs4&password=123456 url编码的形式放置在请求体中，headers：使服务器正确解析参数
    return axios.post("/work/login/login",`name=${username}&password=${password}`,{
        headers:{
            'Content-Type':'application/x-www-form-urlencoded'
        }
    });
}

// http://00000.work:19099/login/register?name=zsname11&password=123456&qq=911412667
export function getShoppingRegister(name,password,qq){
    return axios.post("/work/login/register",`name=${name}&password=${password}&qq=${qq}`,{
        // 作为请求体携带
        headers:{
            'Content-Type':'application/x-www-form-urlencoded'
        }
    })
}

//得到用户信息
// http://00000.work:19099/login/fromUser
export function getFromUser(Authorization){
    // console.log(Authorization);
    //在请求头里面传递Authorization的值
    return axios.post(`/work/login/fromUser`,null,{
        headers:{
            Authorization
        }
    })
}


// 支付参数
//http://00000.work:19099/pay/payShopping?shopping_pay=alipay&shopping_id=1&shopping_sum=1&shopping_qq=911412667
export function getPayGoods(way,id,num,contact,Authorization){
    console.log(way,id,num,contact,Authorization);
    //没有被正确的格式化
    return axios.post("/work/pay/payShopping",{
        shopping_pay: way,
        shopping_id: id,
        shopping_sum: num,
        shopping_qq: contact
    },{
        headers:{
            'Content-Type':'application/x-www-form-urlencoded',
            Authorization,
        }
    })
}